<template>
  <el-dialog
    v-model="dialogVisible"
    :width="width"
    :before-close="handleClose"
    :show-close="false"
    :close-on-click-modal="closeOnClickModal"
    :close-on-press-escape="closeOnPressEscape"
    :top="top"
    :center="center"
    :destroy-on-close="destroyOnClose"
    :class="customClass"
  >
    <template #header="{close}">
         <div class="header_title">{{title}}</div>
         <div class="close-icon" @click="handleCloseClick(close)">
          <img src="@/assets/imgs/home/close.png" class="w-30px h-30px" alt="">
        </div>
    </template>
    <div class="dialog-content">
      <slot name="content"></slot>
    </div>
    <template #footer>
      <slot name="footer"></slot>
    </template>
  </el-dialog>
</template>
    
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
  name: "Dialog",
});
</script>
<script setup lang="ts">
const emit = defineEmits<{
  (e: 'update:dialogVisible', value: boolean): void
  (e: 'close'): void
}>()

const props = withDefaults(defineProps<{
  title: string
  width?: string
  closeOnClickModal?: boolean
  closeOnPressEscape?: boolean
  top?: string
  center?: boolean
  destroyOnClose?: boolean
  customClass?: string
}>(), {
  width: '30%',
  closeOnClickModal: false,
  closeOnPressEscape: true,
  top: '15vh',
  center: false,
  destroyOnClose: false,
  customClass: ''
})

const dialogVisible = defineModel<boolean>('dialogVisible')

// 处理关闭事件
const handleClose = (done: () => void) => {
  emit('close')
  done()
}

// 处理点击关闭按钮事件
const handleCloseClick = (close: () => void) => {
  emit('close')
  close()
}
</script>
    
<style lang="scss" scoped>
</style>